<?php
include('../../include/functions.inc.php');

$list = $db->query_select("cllg_career", "FK_ENTITY=" . $user->entity);

$assign = array("FK_TEACHER" => getParam("ID"), "FK_COURSE" => "", "FK_CYCLE" => "",
    "SECTION" => "", "DAYS" => "", "TIME_BEGIN" => "",
    "TIME_END" => "", "DATE_START" => "", "DATE_END" => "",
    "ID" => "",);
$showDel = false;
if (getParam("IDASSIGN") != NULL) {
    $assign = $db->query_select("cllg_teacher_assign", "ID=" . sqlValue(getParam("IDASSIGN"), "int"));
    $assign = $assign[0];
    $showDel = true;
}

$nameTeach = getParam("NAME");
$nameCourse = "";
if ($assign["FK_TEACHER"] != "") {
    $nameTeach = getTeachName(sqlValue($assign["FK_TEACHER"], "text"), $db);
}
if ($assign["FK_COURSE"] != "") {
    $nameCourse = getCourseName(sqlValue($assign["FK_COURSE"], "int"), $db);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Asignacion de Estudiantes</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script>jQuery.noConflict();</script>
        <script src="../../bootstrap/js/bootstrap.js"></script>
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../js/TableOrderer.js" type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <style type="text/css">
            input,
            textarea{
                width: 300px;
            }
            select{
                width: 315px;
            }
        </style>
        <script type="text/javascript">
            var cargos=null;

            var rsv;
            config=function(){ 
                rsv=new RSV({
                    formID: $(document.ASIGNACION),
                    errorFieldClass: "errorField",
                    rules: ["required,NAME,Debe buscar un Catedratico!",
                        "required,NCURSO,Debe buscar un Curso!",
                        "required,F_INICIO,Ingrese Fecha de Inicio!",
                        "required,F_FINAL,Ingrese Fecha de Fin!",
                        "required,SECTION,Ingrese Fecha de Fin!"],
                    displayType : "display-html",
                    errorHTMLItemBullet : "&#8212; ",
                    onCompleteHandler:function(){
                        waitMsg("Asignado...");
                        backup=$F('operation');
                        if(backup=="edit"){//si es modificacion
                            $(document.ASIGNACION).submit();
                        }else{
                            $('operation').value='prev';
                            $(document.ASIGNACION).request({onComplete:function(r){
                                    if(r.responseJSON.ST==1){
                                        $('operation').value=backup;
                                        $(document.ASIGNACION).submit();
                                    }else{
                                        Dialogs.alert(r.responseJSON.ERROR);
                                    }
                                }});
                        }
							
                    }});
            }

            addOnLoad(config);

            showTeach=function(){
                var f=new Hash({tittle:'Listado de Catedraticos',url:'../teachers/list.php',callback:selTeach,width:500,height:500});
                setList(null,f.toObject());
            }

            showCursos=function(){
                var f=new Hash({tittle:'Listado de Cursos',url:'../courses/list.php',callback:selCourse,width:500,height:500});
                setList(null,f.toObject());
            }

            selTeach=function(s){
                $("ID").value=s.ID;
                $("NAME").value=s.NOMBRES+' '+s.APELLIDOS;	
            }

            selCourse=function(s){
                $("CODE").value=s.CODIGO;
                $("NCURSO").value=s.NOMBRE;	
            }

            cancel=function(){
                var back="<?php echo getenv('HTTP_REFERER'); ?>";
                Dialogs.confirm("Desea cancelar la operacion?",
                function(){
                    $(document.ASIGNACION).action=back;
                    $(document.ASIGNACION).submit();
                },
                function(){});
            }

            del=function(){
                var back="<?php echo getenv('HTTP_REFERER'); ?>";
                Dialogs.confirm("Desea eliminar esta asignacion?",
                function(){
                    $("operation").value="del";
                    $(document.ASIGNACION).submit();
                },
                function(){});
            }


        </script>
    </head>

    <body>
        <div id="tabs">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a>Asignaciones de catedráticos</a>
                </li>
            </ul>
        </div>
        <div id="tab-cont">
            <div id="rsvErrors"></div>
            <form id="ASIGNACION" name="ASIGNACION" method="GET" action="data.php">
                <input type="hidden" name="CYCLE" id="CYCLE" value="<?= getParam("CYCLE") ?>"/>
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th width="50%">
                            &nbsp;
                        </th>
                        <th  width="50%" scope="col">
                            <div class="btn-group">
                                <input type="button" name="cmdOk" id="cmdOk" class="btn btn-info" onClick="rsv.validate();" value="Agregar" />
                                <input name="cmdOk2" type="button" class="btn btn-info" id="cmdOk2" value="Cancelar" onclick="cancel();" />
                                <input name="cmdDel" type="button" class="btn btn-info" id="cmdDel" onclick="del();" value="Eliminar" />
                           </div>
                        </th>

                    </tr>
                    <tr>
                        <td colspan="2">
                            <br/><table width="100%" border="0" cellspacing="0">
                                <tr >
                                    <td width="20%">ID CATEDRATICO</td>
                                    <td width="80%">
                                        <input name="ID" type="text" value="<?php echo $assign["FK_TEACHER"]; ?>" readonly="readonly" id="ID" />          </td>
                                </tr>


                                <tr>
                                    <td>NOMBRE </td>
                                    <td><input name="NAME" type="text" value="<?php echo $nameTeach; ?>" id="NAME" readonly="readonly" size="50" /></td>
                                </tr>

                                <tr>
                                    <td>CARRERA</td>
                                    <td>
                                        <select name="FK_CAREER" id="FK_CAREER">
                                            <option value="">Seleccione</option>
                                            <?php foreach ($list as $car) { ?>
                                                <option value="<?php echo $car["ID"]; ?>" <?php print ( isset($assign["FK_CAREER"]) && $car["ID"] == $assign["FK_CAREER"] ) ? 'selected="selected"' : ''  ?>><?php echo $car["NAME"]; ?> </option>
                                            <?php } ?>
                                        </select>          </td>
                                </tr>
                                <tr>
                                    <td>CURSO</td>
                                    <td><input name="NCURSO" value="<?php echo $nameCourse; ?>" type="text" readonly="readonly" id="NCURSO" />
                                        <input name="buscar2" type="button" onclick="showCursos();" class="btn btn-small" id="buscar2"  value="..." />
                                        <input type="hidden" name="CODE" id="CODE" value="<?php echo $assign["FK_COURSE"]; ?>" /></td>
                                </tr>

                                <tr>
                                    <td>SECCION</td>
                                    <td><select name="SECTION" id="SECTION">
                                            <option value="A" <?php
                                            if (!(strcmp("A", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>A</option>
                                            <option value="B" <?php
                                            if (!(strcmp("B", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>B</option>
                                            <option value="C" <?php
                                                    if (!(strcmp("C", $assign["SECTION"]))) {
                                                        echo "selected=\"selected\"";
                                                    }
                                            ?>>C</option>
                                            <option value="D" <?php
                                            if (!(strcmp("D", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>D</option>
                                            <option value="E" <?php
                                            if (!(strcmp("E", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>E</option>
                                            <option value="F" <?php
                                                    if (!(strcmp("F", $assign["SECTION"]))) {
                                                        echo "selected=\"selected\"";
                                                    }
                                            ?>>F</option>
                                            <option value="G" <?php
                                            if (!(strcmp("G", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>G</option>
                                            <option value="H" <?php
                                            if (!(strcmp("H", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>H</option>
                                            <option value="I" <?php
                                                    if (!(strcmp("I", $assign["SECTION"]))) {
                                                        echo "selected=\"selected\"";
                                                    }
                                            ?>>I</option>
                                            <option value="J" <?php
                                            if (!(strcmp("J", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>J</option>
                                            <option value="K" <?php
                                            if (!(strcmp("K", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>K</option>
                                            <option value="L" <?php
                                            if (!(strcmp("L", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>L</option>
                                            <option value="M" <?php
                                            if (!(strcmp("M", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>M</option>
                                            <option value="N" <?php
                                            if (!(strcmp("N", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>N</option>
                                            <option value="O" <?php
                                            if (!(strcmp("O", $assign["SECTION"]))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>>O</option>                       
                                        </select>          </td>
                                </tr>
                                <tr>
                                    <td>DIAS DE CLASE</td>
                                    <td>
                                        <input <?php print isset($assign["LUNES"]) && $assign["LUNES"] == 1 ? 'checked="checked"' : ''; ?> name="LUNES" type="checkbox" id="LUNES" value="1" />&nbsp;Lunes&nbsp;
                                        <input <?php print isset($assign["MARTES"]) && $assign["MARTES"] == 1 ? 'checked="checked"' : ''; ?> name="MARTES" type="checkbox" id="MARTES" value="1" />&nbsp;Martes&nbsp;
                                        <input <?php print isset($assign["MIERCOLES"]) && $assign["MIERCOLES"] == 1 ? 'checked="checked"' : ''; ?> name="MIERCOLES" type="checkbox" id="MIERCOLES" value="1" />&nbsp;Miercoles&nbsp;
                                        <input <?php print isset($assign["JUEVES"]) && $assign["JUEVES"] == 1 ? 'checked="checked"' : ''; ?> name="JUEVES" type="checkbox" id="JUEVES" value="1" />&nbsp;Jueves&nbsp;
                                        <input <?php print isset($assign["VIERNES"]) && $assign["VIERNES"] == 1 ? 'checked="checked"' : ''; ?> name="VIERNES" type="checkbox" id="VIERNES" value="1" />&nbsp;Viernes&nbsp;
                                        <input <?php print isset($assign["SABADO"]) && $assign["SABADO"] == 1 ? 'checked="checked"' : ''; ?> name="SABADO" type="checkbox" id="SABADO" value="1" />&nbsp;Sabado&nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td>HORA INICIO</td>
                                    <td><input value="<?php echo $assign["TIME_BEGIN"]; ?>" name="H_INICIO" type="text" id="H_INICIO" /></td>
                                </tr>
                                <tr>
                                    <td>HORA FIN</td>
                                    <td><input name="H_FIN" type="text"  id="H_FIN" value="<?php echo $assign["TIME_END"]; ?>" /></td>
                                </tr>
                                <tr>
                                    <td>FECHA DE INICIO</td>
                                    <td><input name="F_INICIO" value="<?php echo $assign["DATE_START"]; ?>" type="text" readonly="readonly" id="F_INICIO" /></td>
                                </tr>
                                <tr>
                                    <td>FECHA DE FINALIZACION</td>
                                    <td><input name="F_FINAL" type="text"  id="F_FINAL" value="<?php echo $assign["DATE_END"]; ?>" readonly="readonly" /></td>
                                </tr>
                                <script >
                                    new Control.DatePicker('F_INICIO', {icon: '../../js/protocalendar/calendar.png',dateFormat: 'yyyy-MM-dd'});
                                    new Control.DatePicker('F_FINAL', {icon: '../../js/protocalendar/calendar.png',dateFormat: 'yyyy-MM-dd'});
                                </script>


                            </table></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="hidden" name="operation" id="operation" value="<?php echo getParam("operation"); ?>" />
                            <input type="hidden" value="<?php echo getParam("IDASSIGN"); ?>"  name="IDASSIGN" id="IDASSIGN" /></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
